-- Winter Anathema (c) v.v.balashoff
local Color = require('libs/colorlibrary/colorlibrary')
local Domain = require('leviathan/ECS/Domain')
local Entity = require('leviathan/ECS/Entity')
local FadeComponent = require('leviathan/ECS/UI/Components/FadeComponent')
local i18n = require('libs/i18n')
local TextComponent = require('leviathan/ECS/UI/Components/TextComponent')
local UIFadeSystem = require('leviathan/ECS/UI/Systems/FadeSystem')
local UIRenderSystem = require('leviathan/ECS/UI/Systems/RenderSystem')

local PressAnyKey = Domain:derive('PressAnyKey')

function PressAnyKey:new(world)
    -- call parent constructor
    PressAnyKey.super.new(self, world, 'PressAnyKey')
    -- get screen size
    local screenW, screenH = love.window.getMode()
    -- get managers
    local FontsManager = world:getManager('FontsManager')
    local fontName = 'CourierNewCyrBold'

    local height = math.floor(screenH * 0.03) -- 3% of screen height
    local font = FontsManager:getFont(fontName, height)

    local y = math.floor(screenH - height * 2) -- 97% of screen height
    local width = screenW
    -- set buffer size
    self.buffer.worldX = 0
    self.buffer.worldY = y
    self.buffer.w = width
    self.buffer.h = height * 1.5 -- fix: fit bottom of english 'y'

    -- entity: press any key
    local press = Entity(self, 'PrefacePressAny', 0, 0, width, height)
    local txt = '[ '..i18n.translate('PressAnyKey')..' ]'
    local pressText = TextComponent('PressAny', 0, 0, width, height, txt, font, Color.black, 'center')
    press:addComponent(pressText)

    -- fade in
    self.buffer.alpha = 0 -- default invisible
    local faderIn = Entity(self, 'FaderIn', 0, 0, screenW, screenH)
    local finComp = FadeComponent('FadeInComponent', self.buffer, 1, 'inOutSine', 1)
    faderIn:addComponent(finComp)
    -- systems
    local fade = UIFadeSystem(self)
    local render = UIRenderSystem(self)
    -- loading systems
    PressAnyKey:addSystem(self, fade)
    PressAnyKey:addSystem(self, render)
end

return PressAnyKey
